<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JS3种对象</title>
</head>
<body>

<script>
    // 1.创建一个JS类型的person对象，属性名：userName、realName、age给三个属性赋值。对应服务器端的一个Java对象
    let person = {
        userName: "齐天大圣",
        realName: "孙悟空",
        age: 501
    };
    // 输出每个属性，取值：对象名.属性名
    document.write(`昵称: ${person.userName} ,真名: ${person.realName} ,年龄: ${person.age}` + "<br/>");

    // 2.创建一个数组，其中每个元素是JS对象，对应服务器端的List<Java对象>
    let brothers = [
        {
            userName: "齐天大圣",
            realName: "孙悟空",
            age: 501
        },
        {
            userName: "天蓬元帅",
            realName: "猪八戒",
            age: 320
        },
        {
            userName: "卷帘大将",
            realName: "沙悟净",
            age: 203
        }
    ];
    // 输出每个元素
    for (let p of brothers) {
        document.write(`昵称: ${p.userName} ,真名: ${p.realName} ,年龄: ${p.age}` + "<br/>");
    }

    // 3.对象的某个属性是一个集合, name为:唐三藏,address为:"大唐", "五指山", "高老庄", "女儿国"
    let boss = {
        name: "唐三藏",
        address: ["大唐", "五指山", "高老庄", "女儿国"]
    };
    document.write(`姓名: ${boss.name} ,地址: ${boss.address}` + "<br/>");
    // 遍历地址
    for (let addr of boss.address) {
        document.write(addr + "<br/>");
    }
</script>
</body>
</html>